#include <stdio.h>
#include <string.h>
#include "kvec.h"
#include "klist.h"
#include "khash.h"

typedef void* WatcherPtr;

#define _noop(x)
KLIST_INIT(WatcherPtr, WatcherPtr, _noop)
void kvec_test(void) { kvec_t(int) array = KV_INITIAL_VALUE; kv_push(array, 10); // append
  kv_a(array, 20) = 5; // dynamic
  printf("value: %d\n", kv_A(array, 20));
  kv_A(array, 20) = 4; // static
  printf("value: %d\n", kv_A(array, 20));
  int sz = kv_size(array);
  printf("sz: %d\n", sz);
  kv_destroy(array);
  return;
}

void klist_test(void)
{
  klist_t(WatcherPtr) *clist = NULL;
  clist = kl_init(WatcherPtr);

  kl_iter(WatcherPtr, clist, current) {
    printf("[%s %d] value: %p\n", __FUNCTION__, __LINE__, (*current)->data);
  }

  char *dat1 = strdup("hello klist!");
  printf("dat1: %p\n", dat1);
  kl_push(WatcherPtr, clist, dat1);

  dat1 = strdup("hello klist 112!");
  printf("dat1: %p\n", dat1);
  kl_push(WatcherPtr, clist, dat1);

  // 遍历klist
  kliter_t(WatcherPtr) **node = NULL;
  kl_iter(WatcherPtr, clist, current) {
    printf("[%s %d] value: %p\n", __FUNCTION__, __LINE__, (*current)->data);
  }
  WatcherPtr tmp = kl_shift(WatcherPtr, clist);
  printf("[%s %d] tmp: %p\n", __FUNCTION__, __LINE__, tmp);
  free(tmp);
  kl_iter(WatcherPtr, clist, current) {
    printf("[%s %d] value: %p\n", __FUNCTION__, __LINE__, (*current)->data);
  }

  kl_destroy(WatcherPtr, clist);
  return;
}

KHASH_MAP_INIT_INT(32, char)

static void khash_test()
{
  int ret , is_missing;
  khiter_t k;
  khash_t(32) *h = kh_init(32);
  k = kh_put(32, h, 5, &ret);
  kh_value(h, k) = 10;
  k = kh_get(32, h, 10);
  is_missing = (k == kh_end(h));
  k = kh_get(32, h, 5);
  kh_del(32, h, 5);
  for (k = kh_begin(h); k != kh_end(h); ++k)
  {
    if (kh_exist(h, k))
    {
      kh_value(h, k) = 1;
    }
  }

  kh_destroy(32, h);
  return;
}

int main() {
  return 1;
}

